package com.aaa.custom.service.productsService;

import com.aaa.custom.dao.Products.ProductsDao;
import com.aaa.custom.dao.orderDao.OrderDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * fileName:ProductsServiceImpl
 * description:
 * author:zxh
 * createTime:2020/3/21 8:23
 * version:1.0.0
 */
@Service
public class ProductsServiceImpl implements ProductsService {
   @Autowired
    private ProductsDao productsDao;


    @Override
    public Integer ProductStockAddbyId(Long product_id, Integer productAmount) {
        return productsDao.ProductStockAddbyId(product_id,productAmount);
    }

    @Override
    public Integer ProductStockSubtractbyId(Long product_id, Integer productAmount) throws Exception {
        Integer stock=productsDao.ProductStockbyId(product_id);
        if (productAmount>stock){
            return productsDao.ProductStockSubtractbyId(product_id,productAmount);
        }else {
            throw new Exception("库存不足");
        }
    }
}
